Skip to content

fix: serialization of box/lasso select data for multiple subplots - #5710

Open
flpi-sun wants to merge 1 commit into
plotly:mainfrom
flpi-sun:fix/#5703-box-select-serialization-with-multiple-subplots
Open

fix: serialization of box/lasso select data for multiple subplots#5710
flpi-sun wants to merge 1 commit into
plotly:mainfrom
flpi-sun:fix/#5703-box-select-serialization-with-multiple-subplots

Conversation

@flpi-sun

@flpi-sun flpi-sun commented Aug 24, 2026

Copy link
Copy Markdown

Closes #5703

Description of change

Include all xNranges / yNranges in selector_state.
This enables getting the box selection size in any number of subplots.

Demo

Aufzeichnung 2026-08-24 150718

Testing strategy

I created the following python file for testing called test_subplot_selection.py:

"""
Test script to verify subplot-specific selector keys are preserved.

Run with:
  solara run test_subplot_selection.py

Then:
1. Click "Box Select" tool in the toolbar
2. Make a selection in the SECOND subplot (Bar chart) - NOT the first one
3. Check the console output for the selector data
4. Verify that x2range and y2range (or similar x2, y2 keys) are present in selector_state
"""

import plotly.graph_objects as go
import solara
from plotly.subplots import make_subplots
import json


def build_figure() -> go.Figure:
    fig = make_subplots(rows=1, cols=2, subplot_titles=("Scatter", "Bar"))
    fig.add_trace(
        go.Scatter(x=[1, 2, 3, 4, 5, 6], y=[2, 1, 3, 5, 4, 6], name="Series A"),
        row=1,
        col=1,
    )
    fig.add_trace(
        go.Bar(x=["A", "B", "C"], y=[3, 1, 2], name="Series B"), row=1, col=2
    )
    fig.update_layout(title="FigureWidget example with 2 subplots")
    return fig


@solara.component
def Page():
    selection_data, set_selection_data = solara.use_state(None)
    def on_selection(data):
        set_selection_data(data)
    with solara.Column():
        solara.FigurePlotly(build_figure(), on_selection=on_selection)
        if selection_data:
            with solara.Column():
                solara.Markdown("### Last Selection Data (Pretty-printed)")
                solara.Markdown(
                    f"```json\n{json.dumps(selection_data, indent=2, default=str)}\n```"
                )

Guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: deserialization of xrange of box select in figure with multiple subplots broken

2 participants